package org.wzl.personalwebsite.config;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.wzl.personalwebsite.interceptor.TokenInterceptor;
import org.wzl.personalwebsite.interceptor.WebLogInterceptor;

@Component
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private WebLogInterceptor webLogInterceptor;

    @Resource
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器，拦截所有路径
        registry.addInterceptor(webLogInterceptor)
                .addPathPatterns("/**"); // 可以指定拦截的路径
//                .excludePathPatterns("/login", "/register"); // 可以指定不拦截的路径

        registry.addInterceptor(tokenInterceptor)
                .excludePathPatterns("/user/**", "/log/**");
    }
}
